/**
 *
 * Copyright by Samuel Castro & Joaquim Fonseca, 2011
 * All Rights Reserved
 *
 * NOTES:
 * Please do not redistribute this plugin without my permission
 * Plugin made for private use only
 *
 */
package com.SySammy.sdRankingSys.Listeners;

import com.SySammy.sdRankingSys.Handlers.VocationHandler;
import com.SySammy.sdRankingSys.Handlers.yamlHandler;
import com.SySammy.sdRankingSys.sdRS;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;

public class RPlayerListener extends PlayerListener {

    sdRS plugin;

    public RPlayerListener(sdRS plugin) {
        this.plugin = plugin;
    }

    @Override
    public void onPlayerChat(PlayerChatEvent event) {
        Player Chatter = event.getPlayer();
        VocationHandler VH = new VocationHandler(plugin);
        yamlHandler YH = new yamlHandler(plugin);
        String vocation = VH.PlyVocation(Chatter);
        String level = VH.PlyVocationLvl(Chatter);
        Chatter.setDisplayName(ChatColor.valueOf(YH.getColor(vocation, level)) + "[" + YH.getAcronym(vocation, level) + "]" + ChatColor.WHITE + Chatter.getName());
    }

    @Override
    public void onPlayerJoin(PlayerJoinEvent event) {
        VocationHandler GH = new VocationHandler(plugin);
        Player p = event.getPlayer();

        if (GH.isNewPlayer(p)) {
            GH.RegNewPlayer(p);
            p.getServer().broadcastMessage(ChatColor.DARK_PURPLE + "Give a warm welcome to the newcomer: " + ChatColor.GOLD + p.getName());
        }
    }
}
